#include "stdafx.h"
#include "net/NTPEventArgs.hpp"
#include "net/DNS.hpp"

NET_NAMESPACE_BEGIN

CNTPEventArgs::CNTPEventArgs(const CSocketAddress& address) : m_address(address), m_packet()
{
}

CNTPEventArgs::~CNTPEventArgs()
{
}

std::string CNTPEventArgs::hostName() const
{
	try
	{
		return CDNS::resolve(m_address.host().toString()).name();
	}
	catch (HostNotFoundException&) 
	{
	}
	catch (NoAddressFoundException&) 
	{
	}
	catch (DNSException&)
	{
	}
	catch (IOException&)
	{
	}
	return m_address.host().toString();
}

std::string CNTPEventArgs::hostAddress() const
{
	return m_address.host().toString();
}

const CNTPPacket &CNTPEventArgs::packet()
{
	return m_packet;
}

void CNTPEventArgs::setPacket(CNTPPacket &packet)
{
	m_packet = packet;
}

NET_NAMESPACE_END
